package soar.template.spring.websocket.chat.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.stereotype.Component;

import redis.clients.jedis.JedisPoolConfig;

@Configuration
public class Redis
{
    @Autowired
    private RedisPropertiesMain redisPropertiesMain;

    @Bean(name = "rcfMain")
    public RedisConnectionFactory redisConnectionFactoryGame()
    {
        JedisPoolConfig pool_config = new JedisPoolConfig();
        pool_config.setBlockWhenExhausted(false);
        pool_config.setMaxTotal(100);
        pool_config.setTestOnBorrow(true);
        JedisConnectionFactory factory = new JedisConnectionFactory(pool_config);
        factory.setHostName(redisPropertiesMain.getHost());
        factory.setPort(redisPropertiesMain.getPort());
        return factory;
    }

}

class RedisProperties
{
    private String host = "localhost";
    private int port = 6379;

    public String getHost()
    {
        return host;
    }

    public void setHost(String host)
    {
        this.host = host;
    }

    public int getPort()
    {
        return port;
    }

    public void setPort(int port)
    {
        this.port = port;
    }
}

@Component
@ConfigurationProperties("redis.main")
class RedisPropertiesMain extends RedisProperties
{

}
